package com.sky.service.impl;

import com.sky.pojo.entity.Employee;
import com.sky.mapper.EmployeeMapper;
import com.sky.mapper.UserMapper;
import com.sky.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    EmployeeMapper employeeMapper;

    @Override
    public UserDetails loadByUserName(String username) {
        // 进行查询 员工
        Employee byName = employeeMapper.getByName(username);
        if (byName != null) {
            return new UserDetails() {
                @Override
                public Collection<? extends GrantedAuthority> getAuthorities() {
                    return List.of(new SimpleGrantedAuthority("Test"));
                }

                @Override
                public String getPassword() {
                    return byName.getPassword();
                }

                @Override
                public String getUsername() {
                    return byName.getUsername();
                }
            };
        }
        return null;
    }

}
